package com.example.skillcinema.db.localdb.daos

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.example.skillcinema.db.localdb.tables.CollectionEntity
import com.example.skillcinema.db.localdb.tables.CollectionEntity.CollectionType

@Dao
interface CollectionDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertCollection(collection: CollectionEntity)

    @Query("SELECT * FROM collections WHERE name = :name AND collection_type = :type")
    suspend fun getCollectionByName(
        name: String,
        type: CollectionType = CollectionType.CUSTOM
    ): CollectionEntity?

    @Update
    suspend fun updateCollection(collection: CollectionEntity)

    @Delete
    suspend fun deleteCollection(collection: CollectionEntity)

    @Query("SELECT * FROM collections WHERE collection_id = :id")
    suspend fun getCollectionById(id: Int): CollectionEntity?

    @Query("SELECT * FROM collections WHERE collection_type = :type")
    suspend fun getCollectionsByCollectionType(type: CollectionEntity.CollectionType): List<CollectionEntity>

    @Query("SELECT * FROM collections")
    suspend fun getAllCollections(): List<CollectionEntity>
}